package com.oa.modules.approvalsec1.dao;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.oa.modules.approvalsec1.entity.DataDocumentEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 *
 *
 * @author jiangwei
 * @email 785297226@qq.com
 * @date 2021-04-19 16:12:24
 */
@Mapper
public interface DataDocumentDao extends BaseMapper<DataDocumentEntity> {


    /**
     * 查询总条数
     *
     * @author jiangwei
     * @email 785297226@qq.com
     * @date 2021-04-19 16:12:24
     * @Description 查询分页数据
     */
    @Select("<script>SELECT COUNT( 1 ) FROM (" +
            "select t1.* from data_document t1  " +
            "where 1=1 " +
            "and t1.`STATUS` = #{params.status} " +
            "<if test='params.companyName != null'> and t1.company_name LIKE '%${params.companyName}%'  </if> " +
            "<if test='params.lowerCategory != null'> and t1.lower_category = #{params.lowerCategory}  </if> " +
            "<if test='params.topCategory != null'> and t1.top_category = #{params.topCategory}  </if> " +
            "<if test='params.companyName2 != null'> and t1.company_name = #{params.companyName2}  </if> " +
            "<if test='params.lowerCategory == null and params.topCategory == null'> " +
            " GROUP BY t1.company_name " +
            "</if> " +
            ") " +
            "TOTAL</script>")
    long findPage(@Param("params") Map<String, Object> params);

    /**
     * 查询分页数据
     *
     * @author jiangwei
     * @email 785297226@qq.com
     * @date 2021-04-19 16:12:24
     * @Description 查询分页数据
     */
    @Select("<script>select t1.* from data_document t1 " +
            "where 1=1 " +
            "and t1.`STATUS` = #{params.status} " +
            "<if test='params.companyName != null'>and t1.company_name LIKE '%${params.companyName}%'  </if> " +
            "<if test='params.lowerCategory != null'> and t1.lower_category = #{params.lowerCategory}  </if> " +
            "<if test='params.topCategory != null'> and t1.top_category = #{params.topCategory}  </if> " +
            "<if test='params.companyName2 != null'> and t1.company_name = #{params.companyName2}  </if> " +
            "<if test='params.lowerCategory == null and params.topCategory == null'> " +
            " GROUP BY t1.company_name " +
            "</if> " +
            "ORDER BY t1.CREATE_DATE desc " +
            "</script>")
    List<DataDocumentEntity> findRecords(IPage<DataDocumentEntity> page, @Param("params") Map<String, Object> params);

    DataDocumentEntity findDataDocumentById(@Param("params") Map<String, Object> params);

}
